package com.dinzeer.lostbladereborn.sa;

import com.dinzeer.legendreliclib.lib.compat.slashblade.Drives;
import com.dinzeer.lostbladereborn.entity.DriveEntityHeal;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.entity.EntityDrive;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;

import static com.dinzeer.legendreliclib.lib.compat.slashblade.Drives.DriveBaseSet;

public class Healis {
    public static void doSlash(LivingEntity entity){
        spawnCircularDrives(entity,8,80,0,10);
    }
    public static void spawnCircularDrives(LivingEntity playerIn, int numPoints, float damage, float roll, float lifetime) {
        int colorCode = (Integer)playerIn.getMainHandItem().getCapability(ItemSlashBlade.BLADESTATE).map((state) -> state.getColorCode()).orElse(-13421569);
        Vec3 lookAngle = playerIn.getLookAngle();
        Vec3 pos = playerIn.position().add((double)0.0F, (double)(playerIn.getEyeHeight() * 0.75F), (double)0.0F).add(lookAngle.scale((double)0.3F));

        for(int i = 0; i < numPoints; ++i) {
            double angleDeg = (double)360.0F / (double)numPoints * (double)i;
            double angleRad = Math.toRadians(angleDeg);
            double offsetX = Math.cos(angleRad);
            double offsetZ = Math.sin(angleRad);
            DriveEntityHeal drive = new DriveEntityHeal(SlashBlade.RegistryEvents.Drive, playerIn.level());
            drive.setPos(pos.x, pos.y, pos.z);
            DriveBaseSet(drive, damage / (float)numPoints, playerIn, colorCode, roll, lifetime);
            Vec3 driveDirection = (new Vec3(offsetX, (double)0.0F, offsetZ)).normalize();
            drive.shoot(driveDirection.x, driveDirection.y, driveDirection.z, drive.getSpeed(), 0.0F);
            playerIn.level().addFreshEntity(drive);
        }

    }
}
